package com.atguigu.lease.admin.controller;

import com.atguigu.lease.admin.service.PaymentTypeService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.PaymentType;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LOGIN
 * @title PaymentInfoController
 * @create 2025/6/21 10:11
 * @description
 */
@RestController
@RequestMapping("/admin/payment")
@Tag(name="支付方式管理模块")
public class PaymentInfoController {
    @Autowired
    PaymentTypeService paymentTypeService;
    @GetMapping("/list")
    @Operation(summary = "1、查询所有支付方式")
    public Result<List<PaymentType>> list(){
        return Result.ok(paymentTypeService.list());
    }

    ///admin/payment/saveOrUpdate
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "2、新增或更新支付方式")
    public Result saveOrUpdate(@RequestBody PaymentType paymentType){
        return Result.ok(paymentTypeService.saveOrUpdate(paymentType));

    }

    @GetMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "查询支付方式分页数据")
    public Result<Page<PaymentType>> page(
           @Parameter(description = "页码") @PathVariable("pageNum") long pageNum,
           @Parameter(description = "每页页码数")@PathVariable("pageSize") long pagesize
    ){
        return  Result.ok(paymentTypeService.page(new Page<PaymentType>(pageNum, pagesize)));
    }
    //admin/payment/deleteById?id=16
    @DeleteMapping("deleteById")
    @Operation(summary = "根据id删除支付方式")
    public Result deleteById(@Parameter(description = "主键值" , in = ParameterIn.QUERY,required = true) @RequestParam("id")Long id){
        return Result.ok(paymentTypeService.removeById(id));
    }

}
